package net.java.mediasystems.database.core.service.impl;

import java.util.List;

import org.springframework.transaction.annotation.Transactional;

import net.java.mediasystems.database.core.model.Metadata;
import net.java.mediasystems.database.core.repository.jpa.MetadataRepository;
import net.java.mediasystems.database.core.service.MetadataService;

public class MetadataServiceImpl implements MetadataService {

	private MetadataRepository metadataRepository;
	
	/**
	 * {@inheritDoc}
	 */
	@Transactional
	@Override
	public Metadata addMetadata(Metadata metadata) {
		return this.metadataRepository.save(metadata);
	}
	
	/**
	 * {@inheritDoc}
	 */
	@Transactional(readOnly = true)
	@Override
	public List<Metadata> getAllMetadataDefinitionByCategory(String category) {
		return this.metadataRepository.findAllByCategory(category);
	}
	
	/**
	 * {@inheritDoc}
	 */
	@Transactional(readOnly = true)
	@Override
	public List<Metadata> getAllMetadataDefinitions() {
		return this.metadataRepository.findAll();
	}
	
	/**
	 * {@inheritDoc}
	 */
	@Transactional(readOnly = true)
	@Override
	public Metadata getMetadataDefinitionByCategoryAndName(String category, String name) {
		return this.metadataRepository.findByCategoryAndNameIgnoreCase(category, name);
	}

	public void setMetadataRepository(MetadataRepository metadataRepository) {
		this.metadataRepository = metadataRepository;
	}
}
